<template>
  <view class="tab-control">
    <view v-for="(item, index) in titles"
         class="tab-control-item"
         :key="index"
         :class="{active: index === currentIndex}"
         @click="itemClick(index)">
      <text>{{item}}</text>
    </view>
  </view>
</template>

<script>
  export default {
    name: "TabControl",
    props: {
      titles: {
        type: Array,
        default() {
          return []
        }
      }
    },
    data() {
      return {
        currentIndex: 0
      }
    },
    methods: {
      itemClick(index) {
        this.currentIndex = index;
        this.$emit('tabClick', index)
      }
    }
  }
</script>

<style scoped>
  .tab-control {
    display: flex;
    text-align: center;
    /* font-size: 16rpx; */
    height: 100rpx;
    line-height: 100rpx;
    background-color: #fff;
		box-sizing: border-box;
  }

  .tab-control-item {
    flex: 1;
  }

  .tab-control-item text {
    padding: 10rpx;
  }

  .active {
    color: red;
  }

  .active text {
    border-bottom: 4rpx solid pink;
  }
</style>
